package com.sec.android.app.myfiles.feature;

import android.content.Intent;
import android.content.res.Configuration;

import com.sec.android.app.myfiles.activity.FileListActivity;
import com.sec.android.app.myfiles.activity.FolderSelectorBottomSheetActivity;
import com.sec.android.app.myfiles.activity.GetMoreSpaceActivity;
import com.sec.android.app.myfiles.common.PickerActivity;
import com.sec.android.app.myfiles.feature.layout.AbsLayoutImp;
import com.sec.android.app.myfiles.feature.layout.FolderSelectorBottomSheetLayoutImp;
import com.sec.android.app.myfiles.feature.layout.SingleLayoutImp;
import com.sec.android.app.myfiles.feature.layout.split.NoteLayoutImp;
import com.sec.android.app.myfiles.feature.layout.split.TabletLayoutImp;
import com.sec.android.app.myfiles.info.AppFeatures;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.navigation.NavigationChangedObserver.NavigationChangedListener;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

public class LayoutMgr implements NavigationChangedListener {
    private AbsLayoutImp mLayoutImp;

    private AbsLayoutImp getLayoutImp(FileListActivity activity) {
        AbsLayoutImp ret;
        Intent intent = activity.getIntent();
        if (intent != null && intent.getBooleanExtra(FolderSelectorBottomSheetActivity.EXTRA_KEY_FOLDER_SELECTOR_BOTTOM_SHEET, false)) {
            ret = new FolderSelectorBottomSheetLayoutImp(activity);
        } else if (AppFeatures.isTabletUIMode()) {
            ret = new TabletLayoutImp(activity);
        } else if (intent != null && intent.getBooleanExtra(GetMoreSpaceActivity.EXTRA_KEY_GET_MORE_SPACE, false)) {
            ret = new SingleLayoutImp(activity);
        } else if (AppFeatures.isNote() && !(activity instanceof PickerActivity)) {
            ret = new NoteLayoutImp(activity);
        } else {
            ret = new SingleLayoutImp(activity);
        }
        Log.d(this, "getLayoutImp : : " + ret.getClass().getSimpleName());
        return ret;
    }

    public AbsLayoutImp getLayoutImp() {
        return mLayoutImp;
    }

    public LayoutMgr(FileListActivity activity) {
        mLayoutImp = getLayoutImp(activity);
    }

    public void onCreate() {
        mLayoutImp.onCreate();
    }

    public void onDestroy() {
        mLayoutImp.onDestroy();
    }

    public void onConfigurationChanged(Configuration newConfig) {
        mLayoutImp.onConfigurationChanged(newConfig);
    }

    @Override
    public void onNavigationChanged(NavigationInfo preInfo, NavigationInfo curInfo) {
        mLayoutImp.onNavigationChanged(preInfo, curInfo);
    }
}
